package com.renchunlin.logindemo01

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.renchunlin.logindemo01.databinding.ActivityMainBinding
import com.renchunlin.logindemo01.domain.QequestUserData
import com.renchunlin.logindemo01.viewModel.OnViewMode

class MainActivity : AppCompatActivity() {

    private val mViewModel by lazy {
        ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()).get(OnViewMode::class.java)
    }

    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initView()
    }

    private fun initView() {
        Glide.with(this)
            .load("https://api.sunofbeach.net/uc/ut/captcha?code=随机数")
            .skipMemoryCache(true)  //验证码不缓存
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(binding.ivCode)


        val userData = QequestUserData("18957806320", "3b811e5e3b816de2e2053e0064e1214c")
        binding.btnLogin.setOnClickListener {
            mViewModel.apply {
                /*loginResult.observe(this@MainActivity, Observer {
                    it.
                })*/

            }.toLogin(binding.etInputCode.text.toString(), userData)
        }
    }
}